//
//  RegisterViewController.m
//  DirectMember
//
//  Created by jzd on 2018/6/20.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollV;
@property (weak, nonatomic) IBOutlet UITextField *nickName;
@property (weak, nonatomic) IBOutlet UITextField *tel;
@property (weak, nonatomic) IBOutlet UITextField *realName;
@property (weak, nonatomic) IBOutlet UITextField *IDCard;
@property (weak, nonatomic) IBOutlet UITextField *loginPwd;
@property (weak, nonatomic) IBOutlet UITextField *sureLogin;
@property (weak, nonatomic) IBOutlet UITextField *secPwd;
@property (weak, nonatomic) IBOutlet UITextField *sureSecPwd;
@property (weak, nonatomic) IBOutlet UITextField *member;
@property (weak, nonatomic) IBOutlet UITextField *recommender;
@property (weak, nonatomic) IBOutlet UITextField *recommenderName;
@property (weak, nonatomic) IBOutlet UITextField *selectArea;
@property (weak, nonatomic) IBOutlet UITextField *jiedianID;
@property (weak, nonatomic) IBOutlet UITextField *selectBaoDan;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"注册";
    
    self.extendedLayoutIncludesOpaqueBars = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapScroll)];
    [self.scrollV addGestureRecognizer:tap];
    
    [self autoScrollViewContentSize];
    
    [self adjustUI];
    
    
}

-(void)adjustUI{
    NSArray *arr = @[self.nickName,self.tel,self.realName,self.IDCard,self.loginPwd,self.sureLogin,self.secPwd,self.sureSecPwd,self.member,self.recommender,self.selectArea,self.jiedianID,self.recommenderName];
    NSArray *img = @[@"userName",@"tel",@"realName",@"idcard",@"pwd",@"",@"pwdSec",@"",@"huiyuan",@"tuijianren",@"selectArea",@"jiedan",@"tuijianName"];
    
    for (int i = 0; i <arr.count ; i++) {
        UITextField *tex = arr[i];
        [self setTextFiled:tex AndLeftImg:img[i]];
    }
    
    
}
-(void)setTextFiled:(UITextField *)textFiled AndLeftImg:(NSString *)img{
    
    UIImage *image = [UIImage imageNamed:img];
    
    UIImageView *ivg = [[UIImageView alloc] initWithImage:image];
    UIView *lvg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 35)];//宽度根据需求进行设置，高度必须大于 textField 的高度
    ivg.center = lvg.center;
    [lvg addSubview:ivg];
    
    //设置 textField 的左侧视图
    //设置左侧视图的显示模式
    textFiled.leftViewMode = UITextFieldViewModeAlways;
    textFiled.leftView = lvg;
}

-(void)tapScroll{
    [self.scrollV endEditing:YES];
}
-(void)autoScrollViewContentSize{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardHidn:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)keyBoardShow:(NSNotification *)noti{
    //获取键盘的高度
    NSDictionary *userInfo = [noti userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int height = keyboardRect.size.height;
    
    
    self.scrollV.contentSize = CGSizeMake(self.scrollV.contentSize.width, 750+height);
    
}
-(void)keyBoardHidn:(NSNotification *)noti{
    self.scrollV.contentSize = CGSizeMake(self.scrollV.contentSize.width, 750);
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
